import { qiniu, init } from "./config.js"

export const putFile = function() {
    //资源上传

    // var localFile = "./src/qiniu/2.jpg";
    
    // var key = '11.jpg';
    var key = "a.json";
    let { config, bucketManager, uploadToken } = init({ scope: 'xmplus:' + key });

    var formUploader = new qiniu.form_up.FormUploader(config);
    var putExtra = new qiniu.form_up.PutExtra();

    // 文件上传
    formUploader.putFile(uploadToken, key, localFile, putExtra, function(respErr,
        respBody, respInfo) {
        if (respErr) {
            throw respErr;
        }
        if (respInfo.statusCode == 200) {
            console.log("图片上传成功", respBody);
        } else {
            console.log("图片上传失败", respBody);
            console.log(respInfo.statusCode);
            console.log(respBody);
        }
    });
}

